import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    meta:{
      showTab: true,
      num:0,
    }
  },
  {
    path: '/search',
    name: 'search',
    component: ()=>import('../views/search'),
    meta: {
      showTab: false
    }
  },
  {
    path: '/theme',
    name: 'theme',
    component: ()=>import('../views/theme'),
    meta: {
      showTab: false
    }
  },
  {
    path: '/newlist',
    name: 'newlist',
    component: ()=>import('../views/newlist'),
    meta: {
      showTab: false
    }
  },
  {
    path: '/class',
    name: 'class',
    component: ()=>import('../views/class'),
    meta: {
      showTab: true,
      num:1,
    }
  },
  {
    path: '/car',
    name: 'car',
    component: ()=>import('../views/car'),
    meta: {
      showTab:true,
      num:2,
    }
  },
  {
    path: '/user',
    name: 'user',
    component: ()=>import('../views/user'),
    meta:{
      showTab:true,
      num:3,
    }
  },
  {
    path: '/ShopList',
    name: 'ShopList',
    component: ()=>import('../views/ShopList'),
    meta: {
      showTab:false,
    }
  },
  {
    path: '/details/:id',
    name: 'details',
    component: ()=>import('../views/details'),
    meta: {
      showTab: false
    }
  },
  {
    path: '/address',
    name: 'address',
    component: () => import('../views/address'),
    meta: {
      showTab: false
    },
  },
  {
    path: '/setaddress',
    name: 'setaddress',
    component: ()=>import('../views/setaddress'),
    meta: {
      showTab: false
    }
  },
  {
    path: '/upaddress/:id',
    name: 'upaddress',
    component: ()=>import('../views/upaddress'),
    meta: {
      showTab: false
    }
  },
  {
    path: '/logoin',
    name: 'login',
    component: ()=>import('../views/logoin'),
    meta: {
      showTab: false
    }
  },
  {
    path: '/register',
    name: 'register',
    component:()=>import('../views/register'),
    meta: {
      showTab: false
    }
  },
  {
    path: '/order',
    name: 'order',
    component:()=>import('../views/order'),
    meta: {
      showTab: false
    }
  },
  {
    path: '/successful',
    name: 'successful',
    component:()=>import('../views/successful'),
    meta: {
      showTab: false
    }
  },
  {
    path: '/orderList',
    name: 'orderList',
    component:()=>import('../views/orderList'),
    meta: {
      showTab: false
    }
  },
  {
    path: '/footprint',
    name: 'footprint',
    component:()=>import('../views/footprint'),
    meta: {
      showTab: false
    },
  },
  {
    path: '/Collection',
    name: 'Collection',
    component:()=>import('../views/Collection'),
    meta: {
      showTab: false
    },
  },
  {
    path: '/Feedback',
    name: 'Feedback',
    component:()=>import('../views/Feedback'),
    meta: {
      showTab: false
    },
  }
]

const router = new VueRouter({
  routes
})

import path from "../store/path";
import {Toast} from "vant";
router.beforeEach((to, from, next)=>{
  let pathArr=['/car']
  if(pathArr.indexOf(to.path)!=-1){
    path.state.topath=to.path;
    let user=JSON.parse(sessionStorage.getItem('user'));
    let token=JSON.parse(sessionStorage.getItem('token'));
    if(token!=null&&user.phone!==''){
        next()
        return
    }
    Toast("请先登录！")
    next('/logoin')
  }
  next()
})

export default router
